package com.usian.admin.listener;

import com.usian.admin.service.WemediaNewsAutoService;
import io.swagger.models.auth.In;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Optional;

import static com.usian.common.constants.message.NewsAutoScanConstants.WM_NEWS_AUTO_SCAN_TOPIC;

/**
 * 自媒体文章自动审核监听类
 */
@Component
public class WemediaNewsAutoListener {

    @Autowired
    private WemediaNewsAutoService wemediaNewsAutoService;

    //监听方法
    @KafkaListener(topics = WM_NEWS_AUTO_SCAN_TOPIC)
    public void receiveMsg(ConsumerRecord<?,?> record){
        //先判断是否存在消息内容
        Optional<? extends ConsumerRecord<?, ?>> optional = Optional.ofNullable(record);
        if(optional.isPresent()){
            //获取消息内容
            String wmNewIdStr = (String) record.value();
            //自媒体文章审核功能
            wemediaNewsAutoService.auditWemediaNews(Integer.parseInt(wmNewIdStr));
        }
    }
}
